from visad import *
from visad.python.JPythonMethods import *
from math import *

[xtype, ytype, ztype] = map(RealType.getRealType,
                            ['x', 'y', 'z'])
xytype = RealTupleType(xtype, ytype)
functype = FunctionType(xytype, ztype)
(xstart, xend, xnum) = (-pi, pi, 100)
(ystart, yend, ynum) = (-pi, pi, 100)
xyset = Linear2DSet(xytype, xstart, xend, xnum, ystart,
                    yend, ynum)
xydata = xyset.getSamples()
zset = Linear1DSet(ztype, 0.0, 0.0, xnum * ynum)
zdata = zset.getSamples()

for i in range(xnum):
    for j in range(ynum):
        index = i * ynum + j
        x = xydata[0][index]
        y = xydata[1][index]
        z = sin(x) * cos(y)
        zdata[0][index] = z
field = FlatField(functype, xyset)
field.setSamples(zdata, 0)
xmap = ScalarMap(xtype, Display.XAxis)
ymap = ScalarMap(ytype, Display.YAxis)
zmap = ScalarMap(ztype, Display.ZAxis)
colormap = ScalarMap(ztype, Display.RGB)

plot('plot3d', field, [xmap, ymap, zmap, colormap])









